Pcap file parsing in Django

by: manishkk, 8 years ago

Last edited: 8 years ago

Hello,
I stardted djnago tutorial from your youtube channel, and achieved half goal which I was trying to implement.

I am trying to parse a pcap file. in which I am able to fetch IP addresses of Source and Destination, Time Stamp & packet length but I am not able to fetch source Mac address and destination mac address.   suggest me something.

right now I am importing these packages:

from django.shortcuts import render

# Create your views here.
from django.shortcuts import render
import dpkt
from django.http import HttpResponse
from pcapfile import savefile
from pcapfile.protocols.linklayer import ethernet
from pcapfile.protocols.network import ip
import binascii


testcap = open('/home/manish/PycharmProjects/pcap/webapp/Test.pcap', 'rb')
capfile = savefile.load_savefile(testcap, verbose=True)

def index(request):
    answer = [
        str(ip.IP(binascii.unhexlify(ethernet.Ethernet(capfile.packets[0].raw()).payload))),
        str(capfile.packets[0].timestamp),
    ]


    return HttpResponse("n".join(answer))

OUTPUT: ipv4 packet from 10.0.0.100 to 255.255.255.255 carrying 52 bytes 1466757757

Thanking you in advance.



You must be logged in to post. Please login or register an account.